Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for missing sem_timedwait on os x #80

Merged
merged 1 commit into from
Mar 5, 2017

Conversation

ghexp
Copy link
Contributor

@ghexp ghexp commented Mar 5, 2017

Follows MIT licensed http://stackoverflow.com/a/37324520
Trying to keep #15 and #36 going

@msftclas
Copy link

msftclas commented Mar 5, 2017

@ghexp,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla.microsoft.com.

It will cover your contributions to all Microsoft-managed open source projects.
Thanks,
Microsoft Pull Request Bot

@msftclas
Copy link

msftclas commented Mar 5, 2017

@ghexp, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, Microsoft Pull Request Bot

Copy link
Contributor

@clovett clovett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that.

@lovettchris lovettchris merged commit e764ea2 into microsoft:master Mar 5, 2017
@lovettchris
Copy link
Member

Actually, I found a simpler implementation using mach, see http://pastebin.com/pm78BJPi.

Turns out mach has semaphore_timedwait.  Can we use this instead?

@ghexp
Copy link
Contributor Author

ghexp commented Mar 5, 2017

@lovettchris
Copy link
Member

http://pastebin.com/pm78BJPi is just a snippet showing how to use a system call, can you verify this works on OSX, if so, I will switch to using semaphore_timedwait using the mach mach_timespec_t.

@ghexp
Copy link
Contributor Author

ghexp commented Mar 6, 2017

Code sample compiles. If you're switching, note that sem_init / sem_destroy (unnamed semaphore) compiles but is also unsupported at run time on OS X, requiring named semaphores instead sem_open/sem_close.
http://stackoverflow.com/questions/1413785/sem-init-on-os-x
http://blog.superpat.com/2010/07/14/semaphores-on-linux-sem_init-vs-sem_open/

@clovett
Copy link
Contributor

clovett commented Mar 7, 2017 via email

@ghexp
Copy link
Contributor Author

ghexp commented Mar 7, 2017

dispatch_semaphore_create is tied to dispatch queues and tasks which are even less POSIX than the limited support for the standard that OS X already provides. "Because Grand Central Dispatch manages the relationship between the tasks you provide and the threads on which those tasks run, you should generally avoid calling POSIX thread routines from your task code."

https://developer.apple.com/library/content/documentation/General/Conceptual/ConcurrencyProgrammingGuide/ThreadMigration/ThreadMigration.html#//apple_ref/doc/uid/TP40008091-CH105-SW18

@clovett
Copy link
Contributor

clovett commented Mar 7, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants